package com.ziyia.alertdialog;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.app.DatePickerDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewParent;
import android.widget.Button;
import android.widget.Toast;

import java.time.LocalDate;
import java.util.PrimitiveIterator;

public class MainActivity extends AppCompatActivity {

    private Button btn1, btn2, btn3, btn4, btn5;
    private View view;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (view == null) {
            view = getLayoutInflater().inflate(R.layout.view, null, true);
        }
        btn1 = findViewById(R.id.btn1);
        btn2 = findViewById(R.id.btn2);
        btn3 = findViewById(R.id.btn3);
        btn4 = findViewById(R.id.btn4);
        btn5 = findViewById(R.id.btn5);
        onBtn1();
        onBtn2();
        onBtn3();
        onBtn4();
        onBtn5();
    }

    private void onBtn1() {

        btn1.setOnClickListener(e -> {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setIcon(R.drawable.ic_launcher_background);
            builder.setMessage("年少有为");
            builder.setCancelable(true);
            AlertDialog alertDialog = builder.create();
            alertDialog.show();
        });
    }
    private void onBtn2() {

        btn2.setOnClickListener(e -> {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setIcon(R.drawable.ic_launcher_background);
            builder.setTitle("提示");
            builder.setView(view);
            builder.setMessage("年少有为");
            builder.setCancelable(true);

            AlertDialog alertDialog = builder.create();
            alertDialog.show();
        });
    }
    /**
     * 没有按钮
     */
    private void onBtn3() {

        btn3.setOnClickListener(e -> {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setIcon(R.drawable.ic_launcher_background);
            builder.setTitle("提示");
            builder.setView(view);
            builder.setMessage("年少有为");
            builder.setCancelable(true);

            // 确定按钮
            builder.setPositiveButton("确定", (d, w) -> {
                Toast.makeText(this, "点击了确定", Toast.LENGTH_SHORT).show();
                        d.dismiss();
                    });

            // 取消按钮
            builder.setNegativeButton("取消", (d, w) ->{
                            Toast.makeText(this, "点击了取消", Toast.LENGTH_SHORT).show();
                            d.dismiss();
                    });

            AlertDialog alertDialog = builder.create();
            alertDialog.show();
        });
    }

    private final void onBtn4() {
        btn4.setOnClickListener(e -> {
            new AlertDialog.Builder(this)
                    .setIcon(R.drawable.ic_launcher_background)
                    .setTitle("提示")
                    .setMessage("年少有为")
                    .setPositiveButton("确定", (d, w) -> {
                        Toast.makeText(this, "点击了确定",Toast.LENGTH_SHORT).show();

                    })
                    .setNegativeButton("取消", (d, w) -> {
                        Toast.makeText(this, "点击了取消", Toast.LENGTH_SHORT).show();
                        d.dismiss();
                    })
                    .setNeutralButton("中间", (d, w) -> {
                        Toast.makeText(this, "点击了中间", Toast.LENGTH_SHORT).show();
                        d.dismiss();
                    })
                    .create()
                    .show();
        });
    }

    private final void onBtn5() {
        btn5.setOnClickListener(e -> {
            new AlertDialog.Builder(this)
                    .setIcon(R.drawable.ic_launcher_background)
                    .setTitle("提示")
                    .setView(view)
                    .setMessage("年少有为")
                    .setPositiveButton("确定", (d, w) -> {
                        Toast.makeText(this, "点击了确定",Toast.LENGTH_SHORT).show();

                    })
                    .setNegativeButton("取消", (d, w) -> {
                        Toast.makeText(this, "点击了取消", Toast.LENGTH_SHORT).show();
                        d.dismiss();
                    })
                    .setNeutralButton("中间", (d, w) -> {
                        Toast.makeText(this, "点击了中间", Toast.LENGTH_SHORT).show();
                        d.dismiss();
                    })
                    .create()
                    .show();
        });
    }
}